import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    num: 200,
    data: null
  },
  mutations: {
    add_num (state, n) {
      state.num += n
    },
    add_reduce (state, n) {
      state.num -= n
    },
    injice (state, data) {
      state.data = data
      // console.log(data)
    }
  },
  actions: {
    requ (context, data) {
      setTimeout(() => {
        context.commit('injice', data)
      }, 2000)
    }
  },
  modules: {
  },
  getters: {
    dbnum: state => {
      return state.num * 2
    },
    three: state => {
      return state.num * 3
    },
    sum: (state, getters) => {
      return getters.three + getters.dbnum
    }
  }
})
